<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>手机号中间四位隐藏</title>
</head>
<body>
    <div id='phone'>17798545749</div>
    <input type="button" value = '隐藏' id="btn">

    <script>
        btn.onclick = function(){
            var phone = document.getElementById('phone');
            var phoneNum = phone.innerText;
            var btn = document.getElementById('btn');
            var replace = phoneNum.substr(4,4);              // 找到要替换的中间4位数字
            var result = phoneNum.replace(replace,'****')

            phone.innerText = result;
        }
    </script>
</body>
</html>